/*
* @file    :mid.c
* @module  :MID
* @author  :LingFengLu
* @date    :2023-06-06
*/

#include "mid.h"
#include "drv.h"

//Constant definition    宏定义
#define BLE_SENSOR_VERSION_STRING "2.0.0" 
NO_INIT(uint32_t dyn_alloc_a[DYNAMIC_MEMORY_SIZE>>2]);
//Global variable definition    全局变量定义


//Private variable definition    私有变量定义


//Private function declaration   私有函数申明
static void ModulesInit(void) ;







//Public function definition   公共函数定义

void Mid_Init(void)
{
	LOG_INFO("BlueNRG-LP BLE Sensor Demo Application (version: %s)\r\n", BLE_SENSOR_VERSION_STRING);
	
#if defined (CONFIG_OTA_HIGHER) /* linker option */
	LOG_INFO("CONFIG_OTA_HIGHER\r\n");
	
#elif defined (CONFIG_OTA_LOWER)  /* linker option */
	LOG_INFO("CONFIG_OTA_LOWER\r\n");
	
#endif
	Code_Init();
	Battery_Init();
	Gc_Init() ;
	ModulesInit() ;
	Ble_InitAdv() ;
}


//Private function definition   私有函数定义

static void ModulesInit(void)
{
	uint8_t ret;
	BLE_STACK_InitTypeDef BLE_STACK_InitParams = BLE_STACK_INIT_PARAMETERS;
	
	LL_AHB_EnableClock(LL_AHB_PERIPH_PKA|LL_AHB_PERIPH_RNG);
	
	
	BLECNTR_InitGlobal();
	DrvTimer_Init () ;
	DrvFlash_Init() ;
	
//	BLEPLAT_Init();  
	
	if (PKAMGR_Init() == PKAMGR_ERROR)
	{
		while(1);
	}
	if (RNGMGR_Init() != RNGMGR_SUCCESS)
	{
		while(1);
	}
	
	/* Init the AES block */
	AESMGR_Init();
	
	/* BlueNRG-LP stack init */
	ret = BLE_STACK_Init(&BLE_STACK_InitParams);
	if (ret != BLE_STATUS_SUCCESS) {
		printf("Error in BLE_STACK_Init() 0x%02x\r\n", ret);
		while(1);
	}
}



